/*
 * AfirmacionDialog.java
 *
 * Created on 24 de septiembre de 2008, 19:15
 */

package com.gilbertoca.igreja.view.dialogs;

import com.gilbertoca.igreja.view.Application;
import org.jdesktop.application.Action;

/**
 *
 * @author  Mono
 */
public class ConfirmationDialog extends javax.swing.JDialog {

    private static Boolean value;

    /** Creates new form AfirmacionDialog */
    public ConfirmationDialog(java.awt.Frame parent, String mensaje) {
        super(parent, Boolean.TRUE);
        initComponents();
        this.mensaje.setText("<html>"+mensaje+"</html>");
        this.setTitle(Application.getApplication().getContext().getResourceMap(Application.class).getString("Application.name"));
    }
    
    @Action
    public void cerrar() {
        dispose();
    }
    
    public static Boolean show(String mensaje) {
        ConfirmationDialog dialog = new ConfirmationDialog(Application.getApplication().getMainFrame(), mensaje);
        dialog.setLocationRelativeTo(Application.getApplication().getMainFrame());
        dialog.setVisible(true);
        return value;
    }

    @Action
    public void cancelar() {
        value = false;
        cerrar();
    }
    @Action
    public void aceptar() {
        value = true;
        cerrar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        mensaje = new javax.swing.JLabel();
        aceptar = new javax.swing.JButton();
        cancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jLabel1.setName("jLabel1"); // NOI18N

        mensaje.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        mensaje.setName("mensaje"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(ConfirmationDialog.class, this);
        aceptar.setAction(actionMap.get("aceptar")); // NOI18N
        aceptar.setName("aceptar"); // NOI18N

        cancelar.setAction(actionMap.get("cancelar")); // NOI18N
        cancelar.setName("cancelar"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(mensaje, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 242, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(114, 114, 114))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(aceptar)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(cancelar)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(mensaje, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(cancelar)
                            .add(aceptar))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptar;
    private javax.swing.JButton cancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel mensaje;
    // End of variables declaration//GEN-END:variables

}
